﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YY.Admin.Services.Service;
using YY.Admin.Services.Service.User;
using YY.Admin.ViewModels.Control;

namespace YY.Admin.ViewModels.SysManage
{
    public class UserManagementViewModel : BaseViewModel
    {
        private PaginationDataGridViewModel<UserOutput> _paginationDataGridViewModel;

        public PaginationDataGridViewModel<UserOutput> PaginationDataGridViewModel
        {
            get => _paginationDataGridViewModel;
            set => SetProperty(ref _paginationDataGridViewModel, value);
        }
        private readonly ISysUserService _sysUserService;
        public UserManagementViewModel(
            ISysUserService sysUserService,
            IContainerExtension container
            ) : base(container)
        {
            _sysUserService= sysUserService;
            // 创建分页控件的 ViewModel，传递一个获取数据的委托
            PaginationDataGridViewModel = new PaginationDataGridViewModel<UserOutput>(FetchUsersAsync);
            _=PaginationDataGridViewModel.LoadData(PaginationDataGridViewModel.PageIndex); // 默认加载第一页数据
        }

        private async Task<(IEnumerable<UserOutput> data, int totalCount)> FetchUsersAsync(int pageIndex, int pageSize)
        {
            var rlt =await _sysUserService.PageAsync(new Services.Service.PageUserInput());
            return (rlt.Items, rlt.Total);  // 返回分页数据和总条目数
        }
    }
}

